﻿using DLL;
using NursingFormSystem.Model;
using NursingFormSystem.NurFormsService;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;

namespace NursingFormSystem.Transfusion
{
    public partial class HistoryTF : Form
    {
        public NursingForm formService = new NursingForm();
        PatientInfo PatientInfo;
        public string Id = string.Empty;
        public HistoryTF(PatientInfo patientInfo)
        {
            InitializeComponent();
            this.PatientInfo = patientInfo;
        }

        private void HistoryTF_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Id", typeof(string));
            dt.Columns.Add("AssessmentDate", typeof(string));
            var ret = formService.GetNursingFormRecordOrderByTime(PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID, (int)FormType.Transfuse, 1);
            if (ret.Code != 1) return;
            List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
            foreach (var record in list)
            {
                DataRow row = dt.NewRow();
                row["Id"] = record.Id;
                row["AssessmentDate"] = Convert.ToDateTime(record.AssessmentDate).ToString("yyyy-MM-dd HH:mm");
                dt.Rows.Add(row);
            }
            gridControl1.DataSource = dt;
        }

        private void bandedGridView1_DoubleClick(object sender, EventArgs e)
        {
            if (bandedGridView1.RowCount > 0)
            {
                string id = bandedGridView1.GetRowCellValue(bandedGridView1.FocusedRowHandle, "Id").ToString();
                Id = id;
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }

        private void btnConfrim_Click(object sender, EventArgs e)
        {
            if (bandedGridView1.RowCount > 0)
            {
                string id = bandedGridView1.GetRowCellValue(bandedGridView1.FocusedRowHandle, "Id").ToString();
                Id = id;
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
